package com.ckm.config;

import com.ckm.annotation.MongoDS;
import com.ckm.aop.DynamicAnnotationAdvisor;
import com.ckm.aop.DynamicAnnotationInterceptor;
import com.ckm.processor.DynamicBeanProcessor;
import org.springframework.aop.Advisor;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.expression.BeanFactoryResolver;

@Configuration(proxyBeanMethods = false)
public class DynamicAopConfig {

//    @Bean
//    @ConditionalOnMissingBean
//    public DynamicBeanProcessor dynamicBeanProcessor(BeanFactory beanFactory){
//        DynamicBeanProcessor processor = new DynamicBeanProcessor();
//        processor.setBeanResolver(new BeanFactoryResolver(beanFactory));
//        return processor;
//    }

    @Bean
    @ConditionalOnMissingBean
    public Advisor advisor (){
        DynamicAnnotationInterceptor dynamicAnnotationInterceptor = new DynamicAnnotationInterceptor();
        DynamicAnnotationAdvisor advisor = new DynamicAnnotationAdvisor(dynamicAnnotationInterceptor, MongoDS.class);
        advisor.setOrder(0);
        return advisor;
    }
}
